import tkinter as tk  
from tkinter import ttk
from middleWare import Middleware  
  
class ScrollTable(tk.Tk):  
    def __init__(self):  
        super().__init__()  
        self.title("请假历史")  
        self.geometry("600x400+{}+{}".format((self.winfo_screenwidth() - 600) // 2, (self.winfo_screenheight() - 400) // 2)) 
        #设置页面logo
        self.iconbitmap("static/favicon.ico")
        self.create_scroll_table()  
  
    def create_scroll_table(self):  
        scrollbar_x = ttk.Scrollbar(self, orient=tk.HORIZONTAL)  
        scrollbar_y = ttk.Scrollbar(self, orient=tk.VERTICAL)  
        lis = ["请假人", "请假天数", "审核教师", "原因", "时间"]  
        tree = ttk.Treeview(self, columns=("请假人", "请假天数", "审核教师", "原因", "时间"), show="headings", xscrollcommand=scrollbar_x.set, yscrollcommand=scrollbar_y.set)  
        scrollbar_x.config(command=tree.xview)  
        scrollbar_y.config(command=tree.yview)  
        scrollbar_x.pack(side=tk.BOTTOM, fill=tk.X)  
        scrollbar_y.pack(side=tk.RIGHT, fill=tk.Y)  
        for col in range(5):  
            tree.heading(lis[col], text=lis[col])  
            tree.column(f"{col}", width=10)  
        result = self.get_his()
        for i in result:  
            tree.insert("", "end", values=(i['leave_user'], i['leave_day'], i['username'], i['leave_desc'], i['time']))  
        tree.pack(fill=tk.BOTH, expand=True)  
        self.mainloop()  
    def get_his(self):
        mid = Middleware()
        ans = mid.data_binding_user_leave()
        return ans
